package com.alibaba.algo.apiimpl.user;

import com.alibaba.algo.cooperation.usercomponent.service.user.SysCurrentOrgService;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SysCurrentOrgDTO;
import com.alibaba.algo.domain.user.SysCurrentOrgDomain;
import com.alibaba.algo.entity.user.SysCurrentOrg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 类SysCurrentOrgServiceImpl.java的实现描述：当前操作组织/部门记录表 serviceimpl
 *
 * @author songwenwei 2021-12-20 16:00:46
*/
@Slf4j
@Service
public class SysCurrentOrgServiceImpl implements SysCurrentOrgService {

    @Autowired
    private SysCurrentOrgDomain sysCurrentOrgDomain;


    @Override
    public void insertOrUpdate(SysCurrentOrgDTO sysCurrentOrgDTO) {
        SysCurrentOrg sysCurrentOrg = new SysCurrentOrg();
        BeanUtils.copyProperties(sysCurrentOrgDTO,sysCurrentOrg);
        // 判断当前用户是否有当前操作部门，有则更新，没有则新增
        SysCurrentOrg sysCurrentOrgEntity = sysCurrentOrgDomain.getByUserId(sysCurrentOrg.getUserId());
        if(ObjectUtils.isEmpty(sysCurrentOrgEntity)){
            sysCurrentOrgDomain.insert(sysCurrentOrg);
        }else{
            sysCurrentOrg.setId(sysCurrentOrgEntity.getId());
            sysCurrentOrgDomain.updateById(sysCurrentOrg);
        }
    }
}
